package com.hbyj.struts.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.hbyj.db.function.DbTools;
import com.hbyj.hbm.vo.FzyaFzya03;
import com.hbyj.hbm.vo.FzyaFzya03temp;
import com.hbyj.hbm.vo.M_set;
import com.hbyj.hbm.vo.YjczYjcz09;
import com.hbyj.hbm.vo.YjczYjcz12;
import com.hbyj.util.ChangeTool;
import com.hbyj.util.Constants;
import com.hbyj.util.PageClass;
import com.opensymphony.xwork2.ActionSupport;

public class YappAction extends ActionSupport{
	private int total;
	private List rows = new ArrayList();
	private String jsonResult;
	public String getJsonResult() {
		return jsonResult;
	}
	public void setJsonResult(String jsonResult) {
		this.jsonResult = jsonResult;
	}
	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}
	public List getRows() {
		return rows;
	}
	public void setRows(List rows) {
		this.rows = rows;
	}
	
	public String queryFzyaList(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		int pageSize = Constants.PAGE_KEY;
		String region = request.getParameter("region");
		String zhlx = request.getParameter("zhlx");
		String gm = request.getParameter("gm");//规模
		String xqdj = request.getParameter("xqdj");//险情等级
		String wxrk = request.getParameter("wxrk");//威胁人口
		String wxcc = request.getParameter("wxcc");//威胁财产
		String qType = request.getParameter("qType");//查询类型  0 已有点  1新增点
		String conStr = "";
		String tbl = "FzyaFzya03";
		String tblJBQK01 = "Jbqk01";
		region = ChangeTool.ChangeArea(region);
		M_set ms = null;
		if(qType!=null&&qType.equals("1")){
			tbl = "FzyaFzya03temp";
			tblJBQK01 = "Jbqk01temp";
		}
		if(!"".equals(gm)){//规模
			ms = ChangeTool.getGMByLevel(zhlx, gm);
			conStr += " and fzya.fzya03190 >"+ms.getMin_v()+" and fzya.fzya03190 <"+ms.getMax_v();
		}
		if(!"".equals(xqdj)){//险情等级
			conStr += " and fzya.fzya03220 = '"+xqdj+"'";
		}
		if(!"".equals(wxrk)){//威胁人口
			conStr += " and fzya.fzya03200 >"+wxrk;
		}
		if(!"".equals(wxcc)){//威胁财产
			conStr += " and fzya.fzya03210 >"+wxcc;
		}
		String hql = "from "+tbl+" fzya,"+tblJBQK01+" jbqk01 where jbqk01.id.jbqk0100 =fzya.fzya03000 and jbqk01.id.jbqk0102=fzya.jbqk0102 and fzya.fzya03000 like '"+region+"%" +zhlx+"____'"+ conStr;
		String countHql = "select count(*) from "+tbl+" fzya,"+tblJBQK01+" jbqk01 where jbqk01.id.jbqk0100 =fzya.fzya03000 and jbqk01.id.jbqk0102=fzya.jbqk0102 and fzya.fzya03000 like '"+region+"%" +zhlx+"____'"+ conStr;
		total = DbTools.getDataHQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(total);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		rows = (List)DbTools.findPageHQL(first, max,hql);
		jsonResult = qType;
		return SUCCESS;
	}
	/**
	 * author cuiyi
	 * time 2012-8-22
	 * disc 更新防灾预案临时表
	 * @return
	 */
	public String updateFzya03TempById(){
		HttpServletRequest request = ServletActionContext.getRequest();
		boolean bl = false;
		String fzya03Str = request.getParameter("fzya03Temp");
		JSONObject obj = JSONObject.fromObject(fzya03Str);
		FzyaFzya03 fzya03 = new FzyaFzya03();
		
		try{
			FzyaFzya03temp fzya03Temp = (FzyaFzya03temp)JSONObject.toBean(obj,FzyaFzya03temp.class);
			bl = DbTools.saveOrUpdateObj(fzya03Temp);
			
			
		}catch (Exception e) {
			System.out.println(e);
		}
		jsonResult =String.valueOf(bl);
		return SUCCESS;
	}
	public String updateFzya03ById(){
		HttpServletRequest request = ServletActionContext.getRequest();
		boolean bl = false;
		String fzya03Str = request.getParameter("fzya03");
		JSONObject obj = JSONObject.fromObject(fzya03Str);
		
		try{
			FzyaFzya03 fzya03 = (FzyaFzya03)JSONObject.toBean(obj,FzyaFzya03.class);
			bl = DbTools.saveOrUpdateObj(fzya03);
			
			
		}catch (Exception e) {
			System.out.println(e);
		}
		jsonResult =String.valueOf(bl);
		return SUCCESS;
	}
	public String insertYYDForXxbs(){
		return SUCCESS;
	}
	
}
